package cn.edu.ctbu.controller.admin;

import cn.edu.ctbu.VO.CountVO;
import cn.edu.ctbu.VO.MemberVO;
import cn.edu.ctbu.VO.OrderStatisticsVO;
import cn.edu.ctbu.VO.TurnoverVO;
import cn.edu.ctbu.result.Result;
import cn.edu.ctbu.service.IOrdersService;
import cn.edu.ctbu.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/admin/statistics")
@Api(tags = "数据相关接口")
public class StatisticsController {
    @Autowired
    IOrdersService iOrdersService;
    @Autowired
    IUserService iUserService;



    @GetMapping("/turnover")
    @ApiOperation("获得营业额数据")
    public Result<TurnoverVO> turnover(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startTime,
                           @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endTime){
        TurnoverVO vo=iOrdersService.turnover(startTime,endTime);

        return Result.success(vo);
    }

    /**
     * 获得用户数据
     */
    @GetMapping("/member")
    @ApiOperation("获得用户数据")
    public Result<MemberVO> member(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startTime,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endTime){
        MemberVO memberVO=iUserService.member(startTime,endTime);
        return Result.success(memberVO);
    }

    /**
     * 获取订单数据
     */
    @GetMapping("/orders")
    @ApiOperation("获得订单数据")
    public Result<OrderStatisticsVO> orders(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startTime,
                                            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endTime){
        OrderStatisticsVO vo=iOrdersService.orders(startTime,endTime);
        return Result.success(vo);
    }

    /**
     * 销量前十
     */
    @GetMapping("/count")
    @ApiOperation("获得销量数据")
    public Result<CountVO> counts(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startTime,
                                 @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endTime){
        CountVO vo=iOrdersService.counts(startTime,endTime);
        return Result.success(vo);
    }
}
